package com.jumi.microservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jumi.microservice.domain.AccountLogin;
import com.jumi.microservice.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 日志表 Mapper 接口
 * </p>
 *
 * @author liuz
 * @since 2020-07-18
 */
public interface LogMapper extends BaseMapper<Log> {


    /**
     * 根据账号ID查找改账号登录次数和最后登录时间
     *
     * @param accountId 账号
     * @return AccountLogin
     */
    @Select("SELECT account_id,count(id) loginNum,MAX(operate_time) lastLoginTime " +
            "FROM auth_log " +
            "WHERE account_id = #{accountId} AND operate_type =3 and is_del = 0")
    @Results({
            @Result(column = "account_id", property = "accountId"),
            @Result(column = "loginNum", property = "loginNum"),
            @Result(column = "lastLoginTime", property = "lastLoginTime")
    })
    AccountLogin getLoginNumAndLastLoginTimeByAccountId(@Param("accountId") Long accountId);

}
